#include "nameitem.h"
#include "widget/chatwidget.h"

NameItem::NameItem():
    m_cw            (NULL)
{
}

NameItem::~NameItem()
{
    if(m_cw != NULL)
    {
        delete m_cw;
        m_cw = NULL;
    }
}

void NameItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
    if(m_cw == NULL)
    {
        m_cw = new ChatWidget();
        m_cw->setVisible(true);
        connect(m_cw,SIGNAL(closeevent()),this,SLOT(closeChatWidget()));
    }
    else
    {
        m_cw->setWindowFlags(Qt::Dialog |Qt::WindowStaysOnTopHint);
        //m_cw->show();
        m_cw->setWindowFlags(Qt::Dialog);
        m_cw->show();
    }
}

void NameItem::closeChatWidget()
{
    if(m_cw != NULL)
    {
        delete m_cw;
        m_cw = NULL;
    }
}
